package com.yanqu.road.server.cmd.banquet.cross.goodbanquet;

import com.yanqu.road.pb.banquet.CrossBanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.banquet.CrossBanquetMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

/**
 * @Description
 * @Author cwq
 * @Data 2021/11/9 21:29
 */
@Cmd(code = Protocol.S_CROSS_GOOD_BANQUET_MEMBER, desc = "请求百福宴来宾列表")
public class GoodBanquetGetMemberCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CrossBanquetProto.GoodBanquetMemberListReqMsg reqMsg = CrossBanquetProto.GoodBanquetMemberListReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        // 检查 活动是否开启
        if(!CrossBanquetMgr.isEnterGoodBanquet(activityId)){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        player.sendPacket(CrossProtocol.C2_GOOD_BANQUET_MEMBER, reqMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            CrossBanquetProto.GoodBanquetMemberListRespMsg.Builder respMsg = CrossBanquetProto.GoodBanquetMemberListRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_CROSS_GOOD_BANQUET_MEMBER, respMsg);
        }
    }
}
